<?php 
defined('RUN_KATANA') or die('Restricted access');
switch ($_REQUEST['action'])
{
	case 'new_user':
		$view = 'new_user';
		$forms['new_user']=$shop->getForms('new_user');
		$forms['new_user']->validate($txt, $com);
		if($forms['new_user']->Valid)
		{
			$usr['id'] = $user->findUserId($forms['new_user']->Fields['uname']->Value);
			if($usr['id'] == 0)
			{ 
				$usr['id'] = $user->findUserId('', $forms['new_user']->Fields['email']->Value);
				if($usr['id'] == 0)
				{
					$user->registerUser($forms['new_user']->Fields['uname']->Value, $forms['new_user']->Fields['password2']->Value, $forms['new_user']->Fields['email']->Value); 
					$usr['id'] = $user->findUserId($forms['new_user']->Fields['uname']->Value);
					if($usr['id'] > 0)
					{ 
						$cart->SetUserID($com, $usr['id']); 
						if(!USER_ACTIVATE)
						{ 
							$user->loginUser($forms['new_user']->Fields['uname']->Value, $forms['new_user']->Fields['password2']->Value); 
							$view = 'customer';
						}
					}
				}
				else
				{ $forms['new_user']->Fields['email']->Error = 'Email allready taken'; }
			}
			else
			{ $forms['new_user']->Fields['uname']->Error = 'Username allready taken'; }
		}
		break;
	case 'customer':
		$view = 'customer';
		if(!($userDetails))
		{ 
			$userDetails = new UserDetails($user); 
			$userDetails->LoadDetails;
		}
		
		$forms['customer']=$shop->getForms('customer');
		$forms['customer']->validate($txt, $com);
		
		if($forms['customer']->Valid)
		{
			$userDetails->setName($forms['customer']->Fields['name']->getValue());
			$userDetails->setLastname($forms['customer']->Fields['lastname']->getValue());
			$userDetails->setCompany($forms['customer']->Fields['company']->getValue());
			$userDetails->setAddress($forms['customer']->Fields['address']->getValue());
			$userDetails->setAddress2($forms['customer']->Fields['address2']->getValue());
			$userDetails->setZip($forms['customer']->Fields['zip']->getValue());
			$userDetails->setCity($forms['customer']->Fields['city']->getValue());
			$userDetails->setCountry($forms['customer']->Fields['country']->getValue());
			$userDetails->setPhone($forms['customer']->Fields['phone']->getValue());
			$userDetails->setValid_customer(1);
			$userDetails->saveDetails();
			$view = 'account';
		}
		break;
	default:
		if($user->getId() > 0)
		{
			if(!($userDetails))
			{ 
				$userDetails = new UserDetails($user);
				if($userDetails->getValid_customer() != 1)
				{ $view = 'customer'; }
				else
				{
					if($_GET['edit'] == 'ud')
					{ $view = 'customer'; }
					else
					{
						if($userDetails->getValid_customer() == 1)
						{ 
							if(($_REQUEST['accept'] == 1) || ($_REQUEST['cancel'] == 1))
							{ 
								$order = new Order();
								$order->loadValues($userDetails);
								if($order->getPaymentStatus() < 3)
								{ 
									if($_REQUEST['cancel'] == 1)
									{ $view = 'shipping'; }
									else
									{ $view = 'payment'; }
								}
							}
							else
							{
								$view = 'shipping'; 
								$shipping = new Shipping($userDetails, $cart);
							}
						}
						else
						{ $view = 'new_user'; }
					}
				}
			}
			else
			{ $view = 'customer'; }
		}
		else
		{ $view = 'new_user'; }
		break;
}

?>